From d7c8f927331b5d74949bcdf1fe3970a77277c4a2 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 13 Sep 2021 14:29:31 -0400 Subject: [PATCH] Add gdk_texture_save_to_png_bytes Just expose what we already have available internally, so e.g. tests can use it without static linking. --- gdk/gdktexture.c | 29 ++++++++++++++++++++++++++++- gdk/gdktexture.h | 2 ++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c index 973a6f923a..85b5be28bb 100644 --- a/gdk/gdktexture.c +++ b/gdk/gdktexture.c @@ -690,7 +690,8 @@ gdk_texture_get_render_data (GdkTexture *self, * This is a utility function intended for debugging and testing. * If you want more control over formats, proper error handling or * want to store to a `GFile` or other location, you might want to - * look into using the gdk-pixbuf library. + * use [method@Gdk.Texture.save_to_png_bytes] or look into the + * gdk-pixbuf library. * * Returns: %TRUE if saving succeeded, %FALSE on failure. */ @@ -713,3 +714,29 @@ gdk_texture_save_to_png (GdkTexture *texture, return result; } + +/** + * gdk_texture_save_to_png_bytes: + * @texture: a `GdkTexture` + * + * Store the given @texture in memory as a PNG file. + * Use [ctor@Gdk.Texture.new_from_bytes] to read it back. + * + * If you want to serialize a texture, this is a convenient and + * portable way to do that. + * + * If you need more control over the generated image, such as + * attaching metadata, you should look into an image handling + * library such as the gdk-pixbuf library. + * + * Returns: a newly allocated `GBytes` containing PNG data + * + * Since: 4.6 + */ +GBytes * +gdk_texture_save_to_png_bytes (GdkTexture *texture) +{ + g_return_val_if_fail (GDK_IS_TEXTURE (texture), NULL); + + return gdk_save_png (texture); +} diff --git a/gdk/gdktexture.h b/gdk/gdktexture.h index 927eb11bdf..7e7de473d8 100644 --- a/gdk/gdktexture.h +++ b/gdk/gdktexture.h @@ -91,6 +91,8 @@ void gdk_texture_download_float (GdkTexture GDK_AVAILABLE_IN_ALL gboolean gdk_texture_save_to_png (GdkTexture *texture, const char *filename); +GDK_AVAILABLE_IN_4_6 +GBytes * gdk_texture_save_to_png_bytes (GdkTexture *texture); G_END_DECLS -- 2.30.2